﻿using System;


namespace myLittleC
{
    //класс Token - лексема
    class Token
    {        
        public Token(String iName, Object iValue, TPosition iPos) { Name = iName; Value = iValue; Position = iPos; }
        public TPosition Position { get; private set;}

        public String Name  { get; private set; }
        public Object Value { get; set;}
        public SubTokenType SubType { get; set;}

        public TokenType Type
        {
            get 
            {
                if (SubType == SubTokenType.CttStr)
                    return TokenType.ConstString;
                if (SubType == SubTokenType.CttInt)
                    return TokenType.ConstInt;
                if (SubType == SubTokenType.CttFloat)
                    return TokenType.ConstFloat;
                if (SubType == SubTokenType.Identeficator)
                    return TokenType.Identeficator;
                if (SubType > SubTokenType.ResWordsStarts &&  SubType < SubTokenType.ResWordsFinish)
                    return TokenType.KeyWord;
                if (SubType > SubTokenType.OperationsStart && SubType < SubTokenType.OperationsEnd)
                    return TokenType.Operation;
                if (SubType > SubTokenType.SeporatorStart &&  SubType < SubTokenType.SeporatorEnd)
                    return TokenType.Separator;                
                if (SubType == SubTokenType.EOF)
                    return TokenType.EOF;
               return TokenType.None;
            }
        }

        public override String ToString() 
        {
            switch (Type)
            {    
                case TokenType.ConstFloat:
                case TokenType.ConstInt:
                case TokenType.ConstString:
                    return String.Format("{0} type: {1}, N: {2}, V: {3}", Position, Type, Name, Value);                    
                case TokenType.Identeficator:
                case TokenType.KeyWord:
                case TokenType.Operation:
                case TokenType.Separator:
                    return String.Format("{0} type: {1}, N: {2}", Position, Type, Name, Value); 
            }
             return String.Format("{0} unDefine Type", Position);
        }
    };

   class TPosition
   {
       public TPosition(int iLine, int iCol) { Line = iLine; Col = iCol + (iCol == 0 ? 1 : 0);}
       
       public int Line { get; private set; }
       public int Col { get; private set; }

       public override String ToString() { return "[" + Line + ", " + Col + "]";}
   }

    
}
